home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / src / linux-headers-2.6.28-15 / arch / arm / plat-mxc / include / mach / dma.h < prev    next >
Encoding:
C/C++ Source or Header  |  2009-09-09  |  9.8 KB  |  264 lines

  1. /*
  2.  * Copyright 2004-2008 Freescale Semiconductor, Inc. All Rights Reserved.
  3.  */
  4.  
  5. /*
  6.  * This program is free software; you can redistribute it and/or modify
  7.  * it under the terms of the GNU General Public License version 2 as
  8.  * published by the Free Software Foundation.
  9.  */
  10.  
  11. #ifndef __ASM_ARCH_MXC_DMA_H__
  12. #define __ASM_ARCH_MXC_DMA_H__
  13.  
  14. #define MXC_DMA_DYNAMIC_CHANNEL   255
  15.  
  16. #define MXC_DMA_DONE          0x0
  17. #define MXC_DMA_REQUEST_TIMEOUT   0x1
  18. #define MXC_DMA_TRANSFER_ERROR    0x2
  19.  
  20. /*! This defines the list of device ID's for DMA */
  21. typedef enum mxc_dma_device {
  22.     MXC_DMA_UART1_RX,
  23.     MXC_DMA_UART1_TX,
  24.     MXC_DMA_UART2_RX,
  25.     MXC_DMA_UART2_TX,
  26.     MXC_DMA_UART3_RX,
  27.     MXC_DMA_UART3_TX,
  28.     MXC_DMA_UART4_RX,
  29.     MXC_DMA_UART4_TX,
  30.     MXC_DMA_UART5_RX,
  31.     MXC_DMA_UART5_TX,
  32.     MXC_DMA_UART6_RX,
  33.     MXC_DMA_UART6_TX,
  34.     MXC_DMA_MMC1_WIDTH_1,
  35.     MXC_DMA_MMC1_WIDTH_4,
  36.     MXC_DMA_MMC2_WIDTH_1,
  37.     MXC_DMA_MMC2_WIDTH_4,
  38.     MXC_DMA_SSI1_8BIT_RX0,
  39.     MXC_DMA_SSI1_8BIT_TX0,
  40.     MXC_DMA_SSI1_16BIT_RX0,
  41.     MXC_DMA_SSI1_16BIT_TX0,
  42.     MXC_DMA_SSI1_24BIT_RX0,
  43.     MXC_DMA_SSI1_24BIT_TX0,
  44.     MXC_DMA_SSI1_8BIT_RX1,
  45.     MXC_DMA_SSI1_8BIT_TX1,
  46.     MXC_DMA_SSI1_16BIT_RX1,
  47.     MXC_DMA_SSI1_16BIT_TX1,
  48.     MXC_DMA_SSI1_24BIT_RX1,
  49.     MXC_DMA_SSI1_24BIT_TX1,
  50.     MXC_DMA_SSI2_8BIT_RX0,
  51.     MXC_DMA_SSI2_8BIT_TX0,
  52.     MXC_DMA_SSI2_16BIT_RX0,
  53.     MXC_DMA_SSI2_16BIT_TX0,
  54.     MXC_DMA_SSI2_24BIT_RX0,
  55.     MXC_DMA_SSI2_24BIT_TX0,
  56.     MXC_DMA_SSI2_8BIT_RX1,
  57.     MXC_DMA_SSI2_8BIT_TX1,
  58.     MXC_DMA_SSI2_16BIT_RX1,
  59.     MXC_DMA_SSI2_16BIT_TX1,
  60.     MXC_DMA_SSI2_24BIT_RX1,
  61.     MXC_DMA_SSI2_24BIT_TX1,
  62.     MXC_DMA_FIR_RX,
  63.     MXC_DMA_FIR_TX,
  64.     MXC_DMA_CSPI1_RX,
  65.     MXC_DMA_CSPI1_TX,
  66.     MXC_DMA_CSPI2_RX,
  67.     MXC_DMA_CSPI2_TX,
  68.     MXC_DMA_CSPI3_RX,
  69.     MXC_DMA_CSPI3_TX,
  70.     MXC_DMA_ATA_RX,
  71.     MXC_DMA_ATA_TX,
  72.     MXC_DMA_MEMORY,
  73.     MXC_DMA_FIFO_MEMORY,
  74.     MXC_DMA_DSP_PACKET_DATA0_RD,
  75.     MXC_DMA_DSP_PACKET_DATA0_WR,
  76.     MXC_DMA_DSP_PACKET_DATA1_RD,
  77.     MXC_DMA_DSP_PACKET_DATA1_WR,
  78.     MXC_DMA_DSP_LOG0_CHNL,
  79.     MXC_DMA_DSP_LOG1_CHNL,
  80.     MXC_DMA_DSP_LOG2_CHNL,
  81.     MXC_DMA_DSP_LOG3_CHNL,
  82.     MXC_DMA_CSI_RX,
  83.     MXC_DMA_SPDIF_16BIT_TX,
  84.     MXC_DMA_SPDIF_16BIT_RX,
  85.     MXC_DMA_SPDIF_32BIT_TX,
  86.     MXC_DMA_SPDIF_32BIT_RX,
  87.     MXC_DMA_ASRC_A_RX,
  88.     MXC_DMA_ASRC_A_TX,
  89.     MXC_DMA_ASRC_B_RX,
  90.     MXC_DMA_ASRC_B_TX,
  91.     MXC_DMA_ASRC_C_RX,
  92.     MXC_DMA_ASRC_C_TX,
  93.     MXC_DMA_ESAI_16BIT_RX,
  94.     MXC_DMA_ESAI_16BIT_TX,
  95.     MXC_DMA_ESAI_24BIT_RX,
  96.     MXC_DMA_ESAI_24BIT_TX,
  97.     MXC_DMA_TEST_RAM2D2RAM,
  98.     MXC_DMA_TEST_RAM2RAM2D,
  99.     MXC_DMA_TEST_RAM2D2RAM2D,
  100.     MXC_DMA_TEST_RAM2RAM,
  101.     MXC_DMA_TEST_HW_CHAINING,
  102.     MXC_DMA_TEST_SW_CHAINING
  103. } mxc_dma_device_t;
  104.  
  105. /*! This defines the prototype of callback funtion registered by the drivers */
  106. typedef void (*mxc_dma_callback_t) (void *arg, int error_status,
  107.                     unsigned int count);
  108.  
  109. /*! This defines the type of DMA transfer requested */
  110. typedef enum mxc_dma_mode {
  111.     MXC_DMA_MODE_READ,
  112.     MXC_DMA_MODE_WRITE,
  113. } mxc_dma_mode_t;
  114.  
  115. /*! This defines the DMA channel parameters */
  116. typedef struct mxc_dma_channel {
  117.     unsigned int active:1;    /*!< When there has a active tranfer, it is set to 1 */
  118.     unsigned int lock;    /*!< Defines the channel is allocated or not */
  119.     int curr_buf;        /*!< Current buffer */
  120.     mxc_dma_mode_t mode;    /*!< Read or Write */
  121.     unsigned int channel;    /*!< Channel info */
  122.     unsigned int dynamic:1;    /*!< Channel not statically allocated when 1 */
  123.     char *dev_name;        /*!< Device name */
  124.     void *private;        /*!< Private structure for platform */
  125.     mxc_dma_callback_t cb_fn;    /*!< The callback function */
  126.     void *cb_args;        /*!< The argument of callback function */
  127. } mxc_dma_channel_t;
  128.  
  129. /*! This structure contains the information about a dma transfer */
  130. typedef struct mxc_dma_requestbuf {
  131.     dma_addr_t src_addr;    /*!< source address */
  132.     dma_addr_t dst_addr;    /*!< destination address */
  133.     int num_of_bytes;    /*!< the length of this transfer : bytes */
  134. } mxc_dma_requestbuf_t;
  135.  
  136. #if defined(CONFIG_ARCH_MX27) || defined(CONFIG_ARCH_MX21)
  137. #include <mach/mx2_dma.h>
  138. #else
  139. #include <mach/sdma.h>
  140. #endif
  141.  
  142. /*!
  143.  * This function is generally called by the driver at open time.
  144.  * The DMA driver would do any initialization steps that is required
  145.  * to get the channel ready for data transfer.
  146.  *
  147.  * @param channel_id   a pre-defined id. The peripheral driver would specify
  148.  *                     the id associated with its peripheral. This would be
  149.  *                     used by the DMA driver to identify the peripheral
  150.  *                     requesting DMA and do the necessary setup on the
  151.  *                     channel associated with the particular peripheral.
  152.  *                     The DMA driver could use static or dynamic DMA channel
  153.  *                     allocation.
  154.  * @param dev_name     module name or device name
  155.  * @return returns a negative number on error if request for a DMA channel did not
  156.  *         succeed, returns the channel number to be used on success.
  157.  */
  158. extern int mxc_dma_request(mxc_dma_device_t channel_id, char *dev_name);
  159.  
  160. /*!
  161.  * This function is generally called by the driver at close time. The DMA
  162.  * driver would do any cleanup associated with this channel.
  163.  *
  164.  * @param channel_num  the channel number returned at request time. This
  165.  *                     would be used by the DMA driver to identify the calling
  166.  *                     driver and do the necessary cleanup on the channel
  167.  *                     associated with the particular peripheral
  168.  * @return returns a negative number on error or 0 on success
  169.  */
  170. extern int mxc_dma_free(int channel_num);
  171.  
  172. /*!
  173.  * This function would just configure the buffers specified by the user into
  174.  * dma channel. The caller must call mxc_dma_enable to start this transfer.
  175.  *
  176.  * @param channel_num  the channel number returned at request time. This
  177.  *                     would be used by the DMA driver to identify the calling
  178.  *                     driver and do the necessary cleanup on the channel
  179.  *                     associated with the particular peripheral
  180.  * @param dma_buf      an array of physical addresses to the user defined
  181.  *                     buffers. The caller must guarantee the dma_buf is
  182.  *                     available until the transfer is completed.
  183.  * @param num_buf      number of buffers in the array
  184.  * @param mode         specifies whether this is READ or WRITE operation
  185.  * @return This function returns a negative number on error if buffer could not be
  186.  *         added with DMA for transfer. On Success, it returns 0
  187.  */
  188. extern int mxc_dma_config(int channel_num, mxc_dma_requestbuf_t * dma_buf,
  189.               int num_buf, mxc_dma_mode_t mode);
  190.  
  191. /*!
  192.  * This function would just configure the scatterlist specified by the
  193.  * user into dma channel. This is a slight variation of mxc_dma_config(),
  194.  * it is provided for the convenience of drivers that have a scatterlist
  195.  * passed into them. It is the calling driver's responsibility to have the
  196.  * correct physical address filled in the "dma_address" field of the
  197.  * scatterlist.
  198.  *
  199.  * @param channel_num  the channel number returned at request time. This
  200.  *                     would be used by the DMA driver to identify the calling
  201.  *                     driver and do the necessary cleanup on the channel
  202.  *                     associated with the particular peripheral
  203.  * @param sg           a scatterlist of buffers. The caller must guarantee
  204.  *                     the dma_buf is available until the transfer is
  205.  *                     completed.
  206.  * @param num_buf      number of buffers in the array
  207.  * @param num_of_bytes total number of bytes to transfer. If set to 0, this
  208.  *                     would imply to use the length field of the scatterlist
  209.  *                     for each DMA transfer. Else it would calculate the size
  210.  *                     for each DMA transfer.
  211.  * @param mode         specifies whether this is READ or WRITE operation
  212.  * @return This function returns a negative number on error if buffer could not
  213.  *         be added with DMA for transfer. On Success, it returns 0
  214.  */
  215. extern int mxc_dma_sg_config(int channel_num, struct scatterlist *sg,
  216.                  int num_buf, int num_of_bytes,
  217.                  mxc_dma_mode_t mode);
  218.  
  219. /*!
  220.  * This function is provided if the driver would like to set/change its
  221.  * callback function.
  222.  *
  223.  * @param channel_num  the channel number returned at request time. This
  224.  *                     would be used by the DMA driver to identify the calling
  225.  *                     driver and do the necessary cleanup on the channel
  226.  *                     associated with the particular peripheral
  227.  * @param callback     a callback function to provide notification on transfer
  228.  *                     completion, user could specify NULL if he does not wish
  229.  *                     to be notified
  230.  * @param arg          an argument that gets passed in to the callback
  231.  *                     function, used by the user to do any driver specific
  232.  *                     operations.
  233.  * @return this function returns a negative number on error if the callback
  234.  *         could not be set for the channel or 0 on success
  235.  */
  236. extern int mxc_dma_callback_set(int channel_num, mxc_dma_callback_t callback,
  237.                 void *arg);
  238.  
  239. /*!
  240.  * This stops the DMA channel and any ongoing transfers. Subsequent use of
  241.  * mxc_dma_enable() will restart the channel and restart the transfer.
  242.  *
  243.  * @param channel_num  the channel number returned at request time. This
  244.  *                     would be used by the DMA driver to identify the calling
  245.  *                     driver and do the necessary cleanup on the channel
  246.  *                     associated with the particular peripheral
  247.  * @return returns a negative number on error or 0 on success
  248.  */
  249. extern int mxc_dma_disable(int channel_num);
  250.  
  251. /*!
  252.  * This starts DMA transfer. Or it restarts DMA on a stopped channel
  253.  * previously stopped with mxc_dma_disable().
  254.  *
  255.  * @param channel_num  the channel number returned at request time. This
  256.  *                     would be used by the DMA driver to identify the calling
  257.  *                     driver and do the necessary cleanup on the channel
  258.  *                     associated with the particular peripheral
  259.  * @return returns a negative number on error or 0 on success
  260.  */
  261. extern int mxc_dma_enable(int channel_num);
  262.  
  263. #endif
  264.